package com.eastfair.matching.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.matching.service.MatchingWorkOrderService;
import com.eastfair.venuebooking.api.WorkOrderFeign;
import com.eastfair.venueservice.dto.WorkOrderDTO;
import com.eastfair.venueservice.dto.WorkOrderOperationRecordDTO;
import com.eastfair.venueservice.dto.WorkOrderQuery;
import com.eastfair.venueservice.vo.WorkOrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 业务实现类
 * 工单
 * </p>
 *
 * @author ln
 * @date 2022-10-24
 */
@Slf4j
@Service
public class MatchingWorkOrderServiceImpl implements MatchingWorkOrderService {

    @Resource
    private WorkOrderFeign workOrderFeign;

    @Override
    public Page<WorkOrderVO> queryWorkOrder(PageParams<WorkOrderQuery> workOrderQuery) {
        R<Page<WorkOrderVO>> pageR = workOrderFeign.queryWorkOrder(workOrderQuery);
        if(!pageR.getIsSuccess()){
            throw BizException.wrap(pageR.getCode(),pageR.getMsg());
        }
        return pageR.getData();
    }

    @Override
    public WorkOrderVO queryWorkOrderDetail(WorkOrderQuery workOrderQuery) {
        R<WorkOrderVO> workOrderVOR = workOrderFeign.queryWorkOrderDetail(workOrderQuery);
        if(!workOrderVOR.getIsSuccess()){
            throw BizException.wrap(workOrderVOR.getCode(),workOrderVOR.getMsg());
        }
        return workOrderVOR.getData();
    }

    @Override
    public Boolean receiveWorkOrder(WorkOrderOperationRecordDTO workOrderOperationRecordDTO) {
        R<Boolean> booleanR = workOrderFeign.receiveWorkOrder(workOrderOperationRecordDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Boolean updateWorkOrder(WorkOrderDTO workOrderDTO) {
        R<Boolean> booleanR = workOrderFeign.updateWorkOrder(workOrderDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Boolean revokeWorkOrder(WorkOrderOperationRecordDTO workOrderOperationRecordDTO) {
        R<Boolean> booleanR = workOrderFeign.revokeWorkOrder(workOrderOperationRecordDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Boolean cancelWorkOrder(WorkOrderOperationRecordDTO workOrderOperationRecordDTO) {
        R<Boolean> booleanR = workOrderFeign.cancelWorkOrder(workOrderOperationRecordDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }

    @Override
    public Boolean closeWorkOrder(WorkOrderOperationRecordDTO workOrderOperationRecordDTO) {
        R<Boolean> booleanR = workOrderFeign.closeWorkOrder(workOrderOperationRecordDTO);
        if(!booleanR.getIsSuccess()){
            throw BizException.wrap(booleanR.getCode(),booleanR.getMsg());
        }
        return booleanR.getData();
    }
}
